import '../model/result_model.dart';
import '../model/school_student.dart';
import '../utils/request.dart';

///学校学生接口
class SchoolStudentApi {
  SchoolStudentApi._();

  static final _singlton = SchoolStudentApi._();

  factory SchoolStudentApi() => _singlton;

  ///查询
  Future<SchoolStudentQueryRes> query(final SchoolStudentQueryReq req) =>
      request
          .getHandler(
            path: '/school/${req.schoolId}/student',
            params: req.toMap(),
          )
          .then((res) => SchoolStudentQueryRes.fromModel(res));

  ///加载
  Future<SchoolStudentInfoRes> info(final String id) => request
      .getHandler(path: '/school/student/$id')
      .then((res) => SchoolStudentInfoRes.fromModel(res));

  ///新增
  Future<BaseModelRes> add(final SchoolStudentAddReq req) =>
      request.postHandler(
        path: '/school/${req.schoolId}/student',
        data: req.toMap(),
      );

  ///修改
  Future<BaseModelRes> modify(final SchoolStudentModifyReq req) =>
      request.putHandler(path: '/school/student/${req.id}', data: req.toMap());

  ///删除
  Future<BaseModelRes> delete(final String id) =>
      request.deleteHandler(path: '/school/student/$id');
}

//学校学生接口单例
final schoolStudentApi = SchoolStudentApi();
